package com.lookoutthebush.companyindex.util;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页工具
 *
 * @author LookOutTheBush
 * @date 2021/9/14 8:27 下午
 */
@Data
public class PageHelper<T> {

    private int pageNum;

    private int total;

    private int totalPage;

    private int pageSize;

    private List<T> data;

    public PageHelper() {
        this.pageNum = 1;
        this.total = 0;
        this.totalPage = 0;
        this.pageSize = 0;
        this.data = new ArrayList<>();
    }

    public void setTotal(int total) {
        this.total = total;
        this.totalPage = (int) Math.ceil((double) total / (double) this.pageSize);
    }

    public int getStart() {
        return this.pageNum > 0 ? (this.pageNum - 1) * this.pageSize : 0;
    }
}
